package com.sparrow.controller;

import com.sparrow.bean.User;
import io.swagger.annotations.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import javax.validation.constraints.Email;

/**
 * Created by wancheng on 2018/12/29.
 */
@RestController
@Validated
@Api("swaggerTestController相关api")
public class TestController {

    private  final Logger logger = LoggerFactory.getLogger(TestController.class);


    @ApiOperation(value = "根据id查询学生的信息",notes = "查询数据库中某个学生的信息")
    @ApiImplicitParam(name ="id",value = "学生id",paramType = "path",required = true,dataType = "String")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "用户id",dataType = "String",paramType = "query",example = "1112")
    })
    @ApiResponses({
            @ApiResponse(code=400,message = "请求参数没有填好"),
            @ApiResponse(code=404,message="请求路径没有找到")
    })
    @RequestMapping(value = "/test.do")
    public User test1(@Valid User user){
        System.out.println(user.getUserName());
        return user;
    }
    @RequestMapping(name = "异常测试",value = "/test2.do",method = RequestMethod.GET)
    @ResponseBody
    public String test2() throws Exception {
        throw new Exception("测试异常");
      // return "111111";
    }
}
